//
//  VSaleTableVIewCell.m
//  STL_ Animation
//
//  Created by dllo on 16/4/1.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "VSaleTableVIewCell.h"

@interface VSaleTableVIewCell ()

@property (nonatomic, strong) STLView *backGroundView;
@property (nonatomic, strong) STLImageView *backGroundImageVIew;
@property (nonatomic, strong) STLLabel *scoreLabel;
@property (nonatomic, strong) STLImageView *changeImageView;
@property (nonatomic, strong) STLLabel *trendScoreLabel;
@property (nonatomic, strong) STLLabel *nameLabel;
@property (nonatomic, strong) STLLabel *artistLabel;
@property (nonatomic, strong) CAGradientLayer *layerName;

@end

@implementation VSaleTableVIewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatViews];
        
        
    }
    return self;
}

#pragma mark - creatViews
- (void)creatViews {
    self.backGroundView = [[STLView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:self.backGroundView];
    
    self.backGroundImageVIew = [[STLImageView alloc] initWithFrame:CGRectZero];
    [self.backGroundView addSubview:self.backGroundImageVIew];
    
    self.layerName = [CAGradientLayer layer];
    
    self.layerName.startPoint = CGPointMake(0, 0);
    self.layerName.endPoint = CGPointMake(0, 1);
    self.layerName.colors = @[(__bridge id)[UIColor clearColor].CGColor,(__bridge id)[UIColor blackColor].CGColor];
    self.layerName.locations = @[@(0.5f),@(1.0f)];
    [self.contentView.layer addSublayer:self.layerName];
    
    self.rankingLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.rankingLabel.textColor = [UIColor whiteColor];
    self.rankingLabel.textAlignment = NSTextAlignmentLeft;
    self.rankingLabel.font = [UIFont systemFontOfSize:25];
    [self.contentView addSubview:self.rankingLabel];
    
    self.scoreLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.scoreLabel.textColor = [UIColor whiteColor];
    self.scoreLabel.textAlignment = NSTextAlignmentLeft;
    self.scoreLabel.font = [UIFont systemFontOfSize:20];
    [self.contentView addSubview:self.scoreLabel];
    
    self.changeImageView = [[STLImageView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:self.changeImageView];
    
    self.trendScoreLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.trendScoreLabel.textAlignment = NSTextAlignmentLeft;
    self.trendScoreLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.trendScoreLabel];
    
    self.nameLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.textAlignment = NSTextAlignmentRight;
    self.nameLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.nameLabel];
    
    self.artistLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.artistLabel.textColor = [UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1];
    self.artistLabel.textAlignment = NSTextAlignmentRight;
    self.artistLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.artistLabel];
}

#pragma mark - layoutSubview
- (void)layoutSubviews {
    
    self.backGroundView.frame = self.bounds;
    
    self.backGroundImageVIew.frame = self.bounds;
    
    self.rankingLabel.frame = CGRectMake(10, BoundsHeight - 85, 80, 40);
    
    self.scoreLabel.frame = CGRectMake(self.rankingLabel.frame.origin.x, BoundsHeight - 40, self.rankingLabel.bounds.size.width, 30);
    
    self.changeImageView.frame = CGRectMake(self.scoreLabel.frame.origin.x + self.scoreLabel.bounds.size.width + 5, BoundsHeight - 30, 10, 10);
    
    self.trendScoreLabel.frame = CGRectMake(self.changeImageView.frame.origin.x + self.changeImageView.bounds.size.width + 5, self.changeImageView.origin.y - 5, 80, 20);
    
    self.nameLabel.frame = CGRectMake(BoundsWidth - 310, BoundsHeight - 55, 300, 20);
    self.artistLabel.frame = CGRectMake(self.nameLabel.origin.x, BoundsHeight - 30, 300, 20);
    
    self.layerName.frame = self.backGroundImageVIew.bounds;
}

- (void)setVideosDetailModel:(VSaleVideosDetailModel *)videosDetailModel {
    _videosDetailModel = videosDetailModel;
    
    [self.backGroundImageVIew sd_setImageWithURL:[NSURL URLWithString:_videosDetailModel.playListPic] placeholderImage:[UIImage imageNamed:@"logoimage"]];
    
    
    self.scoreLabel.text = _videosDetailModel.score;
    self.trendScoreLabel.text = _videosDetailModel.trendScore;
    
    if (_videosDetailModel.up == YES) {
        self.trendScoreLabel.textColor = [UIColor redColor];
        if (self.type == 0) {
            self.changeImageView.hidden = NO;
            self.changeImageView.image = [UIImage imageNamed:@"up"];
        } else {
            self.changeImageView.hidden = YES;
        }
        
    } else {
        self.trendScoreLabel.textColor = [UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1];
        if (self.type == 0) {
            self.changeImageView.hidden = NO;
            self.changeImageView.image = [UIImage imageNamed:@"down"];
        } else {
            self.changeImageView.hidden = YES;
        }
        
    }
    
    self.nameLabel.text = _videosDetailModel.title;
    self.artistLabel.text = _videosDetailModel.artistName;
    
}
@end
